import { _decorator, Component, Node, Sprite } from 'cc';
import { BaseView } from '../../../scripts/libs/rxjs/cc3/BaseView';
import { ReactiveProperty } from '../../../scripts/libs/rxjs/cc3/ReactiveProperty';
import { SpriteAtlas } from 'cc';
import { ItemKey } from '../../../scripts/managers/DevConfig';
const { ccclass, property, executeInEditMode } = _decorator;

@ccclass('FlyItem')
@executeInEditMode
export class FlyItem extends BaseView {

    itemKey = ReactiveProperty.Create<ItemKey>(null);

    @property(Sprite)
    iconSprite: Sprite = null;

    @property(SpriteAtlas)
    atlas: SpriteAtlas = null;

    useObserves() {
        return [
            this.itemKey.subscribe(this.refresh.bind(this))
        ];
    }

    refresh() {
        this.iconSprite.spriteFrame = this.atlas.getSpriteFrame(`item_icon/${this.itemKey.value}`);
    }

}

